﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace Elentok.Common.Wpf.Helpers
{
  /// <summary>
  /// Drag and Drop related methods
  /// </summary>
  public static class DragDropHelper
  {

    /// <summary>
    /// Returns true if the data object contains data of type <typeparamref name="T"/>
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="data"></param>
    /// <returns></returns>
    public static bool GetDataPresent<T>(this IDataObject data)
    {
      return data.GetDataPresent(typeof(T));
    }

    /// <summary>
    /// Returns the data of type <typeparamref name="T"/> within the data object.
    /// (returns null if it doesn't exist)
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="data"></param>
    /// <returns></returns>
    public static T GetData<T>(this IDataObject data)
    {
      if (data.GetDataPresent<T>())
        return (T)data.GetData(typeof(T));
      else
        return default(T);
    }

  }
}
